
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>发送通知</title>
 </head>

<body>

<script type="text/javascript">
    var url = 'ws:120.31.131.231:9502';  
    var ws = new WebSocket(url);  
    //ws.bufferedAmount  //表示已在WebSocket上发送但尚未写入网络的字节数。它对于调节发送速率很有用。  
    ws.onopen = function (e) {  
        console.log('链接打开');  
        //e  Event 对象  
        console.info(e);  
        //e.target  --- 当前事件触发对象，也就是 new的WebSocket 对象  
        ws.send('hello ws,当前协议：' + e.target.protocol);  
    }  
    ws.onmessage = function (e) {  
        //e MessageEvent 对象  
        //e.data 从服务器发送过来的数据  
        console.info(e);  
        console.info('接受到数据：' + e.data);  
    }  
    ws.onclose = function (e) {  
        console.info(e);  
        console.log('closed');  
    }  
    ws.onerror = function (e) {  
        console.info(e);  
        console.log('发生异常');  
    }  
</script>
</body>
</html>
